home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / Programming / PPCsiod / sources / repl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-26  |  6.4 KB  |  219 lines

  1. /* Scheme In One Define.
  2.  
  3. The garbage collector, the name and other parts of this program are
  4.  
  5.  *                     COPYRIGHT (c) 1989 BY                              *
  6.  *      PARADIGM ASSOCIATES INCORPORATED, CAMBRIDGE, MASSACHUSETTS.       *
  7.  
  8. Conversion  to  full scheme standard, characters, vectors, ports, complex &
  9. rational numbers, and other major enhancments by
  10.  
  11.  *      Scaglione Ermanno, v. Pirinoli 16 IMPERIA P.M. 18100 ITALY        * 
  12.  
  13. Permission  to use, copy, modify, distribute and sell this software and its
  14. documentation  for  any purpose and without fee is hereby granted, provided
  15. that  the  above  copyright  notice appear in all copies and that both that
  16. copyright   notice   and   this  permission  notice  appear  in  supporting
  17. documentation,  and that the name of Paradigm Associates Inc not be used in
  18. advertising or publicity pertaining to distribution of the software without
  19. specific, written prior permission.
  20.  
  21. PARADIGM  DISCLAIMS  ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  22. ALL  IMPLIED  WARRANTIES  OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  23. PARADIGM  BE  LIABLE  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  24. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  25. IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  26. OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  
  28. */
  29.  
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include <ctype.h>
  33. #include <setjmp.h>
  34. #include <signal.h>
  35. #include <time.h>
  36. #include <math.h>
  37.  
  38. #include "siod.h"
  39.  
  40. void main(int argc, char **argv)
  41. {int flag;
  42.  flag = process_env();
  43.  if((argc==1) && (flag==0))
  44.   {printf("\fSiod, SCHEME interpreter v2.6\n");
  45.    printf("Options:\n");
  46.    printf("        -h<number>   sets the number of cons in siod's\n");
  47.    printf("                     fixed-size heap.\n");
  48.    printf("                     Minimum 1000. Default 5000.\n");
  49.    printf("        -o<number>   sets the number of buckets in siod's\n");
  50.    printf("                     symbols hash table.\n");
  51.    printf("                     Minimum 1. Default 100.\n");
  52.    printf("        -f<number>   sets the number of buckets in siod's\n");
  53.    printf("                     integers hash table.\n");
  54.    printf("                     Minimum 1. Default 100.\n");
  55.    printf("        -i<filename> a file to be loaded in the high-speed\n");
  56.    printf("                     user-global-environment.\n");
  57.    printf("        -q           quiet flag.\n");
  58.    printf("        -s           small set of predefined functions.\n");}
  59.  else
  60.    print_welcome();
  61.  process_cla(argc,argv);
  62.  init_storage();
  63.  print_hs_1();
  64.  init_subr_fond();
  65.  if(full_set == 1)
  66.    init_subrs();
  67.  repl_driver();
  68.  fprintf(stderr,"Siod terminated.\n");
  69.  exit(0);}
  70.  
  71. int process_env(void)
  72. {char *envop;
  73.  int flag=0;
  74.  envop=getenv("SIOD-HEAP-SIZE");
  75.  if(envop)
  76.    {flag=1;
  77.     heap_size = atol(envop);
  78.     if(heap_size<1000)
  79.       heap_size = 1000;}
  80.  envop=getenv("SIOD-SYMTAB-SIZE");
  81.  if(envop)
  82.    {flag=1;
  83.     obarray_dim = atol(envop);
  84.     if(obarray_dim<1)
  85.       obarray_dim = 1;}
  86.  envop=getenv("SIOD-FIXTAB-SIZE");
  87.  if(envop)
  88.    {flag=1;
  89.     fixarray_dim = atol(envop);
  90.     if(fixarray_dim<1)
  91.       fixarray_dim = 1;}
  92.  envop=getenv("SIOD-INIT-FILE");
  93.  if(envop)
  94.   {flag=1;
  95.    init_file=envop;}
  96.  envop=getenv("SIOD-QUIET");
  97.  if(envop)
  98.   {flag=1;
  99.    quiet=(atol(envop)==1)?1:0;}
  100.  envop=getenv("SIOD-SMALL");
  101.  if(envop)
  102.   {flag=1;
  103.    full_set=(atol(envop)==1)?0:1;}
  104.  return(flag);}
  105.  
  106. void repl_driver()
  107. {int k;
  108.  LISP stack_start;
  109.  LISP base_fluid_env=extend_env(cons(val_input_port,
  110.                                      cons(val_output_port,
  111.                                           cons(val_scheme_top_level,
  112.                                                NIL))),
  113.                                 envcons(NIL,NIL));
  114.  stack_start_ptr = &stack_start;
  115.  k = setjmp(errjmp);
  116.  if (k == 2) return;
  117.  signal(SIGFPE,handle_sigfpe);
  118.  signal(SIGINT,handle_sigint);
  119.  signal(SIGABRT,handle_sigabort);
  120.  catch_framep = (struct catch_frame *) NULL;
  121.  errjmp_ok = 0;
  122.  interrupt_differed = 0;
  123.  nointerrupt = 0;
  124.  sym_fluid_environment = base_fluid_env;
  125.  errjmp_ok = 1;
  126.  if (k == 1)
  127.    {gc_for_newcell();
  128.     if(NNULLP(VCELL(sym_on_reset)))
  129.       apply_proc(VCELL(sym_on_reset),NIL,sym_initial_environment);}
  130.  else if (k == 0)
  131.    {if(full_set == 1) vload("siod.scm",NIL);
  132.     if (init_file) vload(init_file,NIL);}
  133.  while(1) 
  134.   {apply_proc(CDR(val_scheme_top_level),NIL,sym_initial_environment);}}
  135.  
  136. LISP scheme_reset(void)
  137. {CDR(val_scheme_top_level)=subrcons(tc_subr_0,
  138.                                     "scheme-top-level",
  139.                                     scheme_top_level);
  140.  CDR(val_output_port)=VCELL(sym_standard_output);
  141.  CDR(val_input_port)=VCELL(sym_standard_input);
  142.  VCELL(sym_inspect) = subrcons(tc_subr_1,"inspect",inspect);
  143.  VCELL(sym_err_han) = subrcons(tc_subr_0,"*error*",error_han);
  144.  longjmp(errjmp,1);
  145.  return(NIL);}
  146.  
  147. LISP reset_scheme_top_lev()
  148. {CDR(val_scheme_top_level)=subrcons(tc_subr_0,
  149.                                     "scheme-top-level",
  150.                                     scheme_top_level);
  151.  return(truth);}
  152.  
  153. void fput_st(FILE *f, char *st)
  154. {long res;
  155.  long flag;
  156.  flag = no_interrupt(1);
  157.  res=fputs(st,f);
  158.  if(transfile) fputs(st,transfile);
  159.  if(res==EOF)
  160.    err("Error during I/O",NIL,ERR_GEN);
  161.  no_interrupt(flag);}
  162.  
  163. FILE *get_cur_out()
  164. {LISP out;
  165.  out = CDR(val_output_port);
  166.  if(NPORTP(out))
  167.    err("current output must be a port",out,ERR_GEN);
  168.  return(PORTPTR(out));}
  169.  
  170. FILE *get_cur_in()
  171. {LISP in;
  172.  in = CDR(val_input_port);
  173.  if(NPORTP(in))
  174.    err("current input must be a port",in,ERR_GEN);
  175.  return(PORTPTR(in));}
  176.  
  177. void put_st(char *st)
  178. {fput_st(get_cur_out(),st);}
  179.  
  180. double myruntime(void)
  181. {long x;
  182.  x = clock();
  183.  return((double) x);}
  184.  
  185. LISP lruntime(void)
  186. {return flocons(myruntime());}
  187.  
  188. LISP scheme_top_level(void) 
  189. {FILE *in,*out;
  190.  int ch;
  191.  LISP x;
  192.  double rt;
  193.  out = get_cur_out();
  194.  clearerr(out);
  195.  fput_st(out,">> ");
  196.  in = get_cur_in();
  197.  clearerr(in);
  198.  x = lreadf(in);
  199.  while(((ch=f_getc(in))!='\n')&&(ch!=EOF));
  200.  if EQ(x,eof_val) {clearerr(in);err("EOF",eof_val,ERR_GEN);}
  201.  gc_cells_allocated = 0;
  202.  gc_time_taken = 0.0;
  203.  rt = myruntime();
  204.  x = leval(x,sym_initial_environment);
  205.  rt = myruntime()-rt;
  206.  out = get_cur_out();
  207.  fput_st(out,"\n");
  208.  if(VCELL(sym_repl_mode)==truth)
  209.     {sprintf(tkbuffer,
  210.         "Evaluation took %g milliseconds (%g in gc) %d cons work\n",
  211.         rt,
  212.         gc_time_taken,
  213.         gc_cells_allocated);
  214.    fput_st(out,tkbuffer);}
  215.  if(NEQ(x,sym_the_non_printing))
  216.    {lprin1f(x,out);
  217.     fput_st(out,"\n");}
  218.  return(NIL);}
  219.